package com.hawthorn.admin.controller.sysbizconf;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.repository.SysBizConfMapper;
import com.hawthorn.admin.service.sysbizconf.SysBizConfService;
import com.hawthorn.platform.annotation.MarkLog;
import com.hawthorn.platform.exception.BizCode;
import com.hawthorn.platform.utils.common.MyUtil;
import com.hawthorn.platform.utils.iassert.AssertMyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * <p>todo 业务参数配置表 controller</p>
 * @author: wcz
 * @created: 2022-07-01
 * @version v1.0.1
 */
@Api(tags = {"admin-sysbizconf"})
@RestController
@RequestMapping("/sysbizconf/")
public class SysBizConfController
{
  @Resource
  public SysBizConfService sysBizConfService;

  /**
   * <p>todo 查询业务参数配置表信息 </p>
   * @author: wcz
   * @date: 2022-07-01
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询->业务参数配置表信息", notes = "查询业务参数配置表信息服务")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "查询条件参数", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findBizConf")
  public IPage<Map<String, Object>> findBizConf(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return sysBizConfService.findBizConf(page, conditions);
  }

  /**
   * <p>todo 保存业务参数配置表</p>
   * @author: wcz
   * @date: 2022-07-01
   * @version: 1.0.1
   */
  @ApiOperation(value = "保存->业务参数配置表", notes = "保存业务参数配置表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "保存参数", dataTypeClass = Map.class)
  })
  @PostMapping(value = "/saveBizConf")
  @MarkLog(value = "新增业务参数-[{0}]", param = "paraName")
  public Map<String, Object> saveBizConf(@RequestBody Map<String, Object> param)
  {
    return sysBizConfService.saveBizConf(param);
  }

  /**
   * <p>todo 更新业务参数配置表</p>
   * @author: wcz
   * @date: 2022-07-01
   * @version: 1.0.1
   */
  @ApiOperation(value = "更新->业务参数配置表", notes = "更新业务参数配置表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
      @ApiImplicitParam(name = "param", value = "更新参数", dataTypeClass = Map.class)
  })
  @PutMapping(value = "/updateBizConf/{id}")
  @MarkLog(value = "更新业务参数-[{0}]", param = "paraName")
  public Map<String, Object> updateBizConf(@PathVariable("id") Long id, @RequestBody Map<String, Object> param)
  {
    return sysBizConfService.updateBizConf(id, param);
  }

  /**
   * <p>todo 导出业务参数配置表</p>
   * @author: wcz
   * @date: 2022-07-01
   * @version: 1.0.1
   */
  @ApiOperation(value = "导出->业务参数配置表", notes = "导出业务参数配置表")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "response", value = "response", dataTypeClass = HttpServletResponse.class),
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/exportBizConfData")
  public void export(HttpServletResponse response, @RequestBody Map<String, Object> param) throws IOException
  {
    AssertMyUtil.notNull(param, BizCode.VARIABLE_NOT_EMPTY, "param");
    sysBizConfService.export(response, "导出数据", param);
  }


  @Resource
  SysBizConfMapper sysBizConfMapper;

  /**
   * <p>todo 删除业务参数</p >
   * @author: WCZ
   * @date: 2022/7/4 15:37
   * @version: 1.0.1
   */
  @ApiOperation(value = "删除->业务参数", notes = "删除业务参数")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "id", dataTypeClass = Long.class)
  })
  @MarkLog(value = "删除业务参数")
  @PostMapping(value = "/removeBizConf/{id}")
  public Integer removeBizConf(@PathVariable("id") Long id)
  {

    return sysBizConfService.removeBizConf(id);
  }

}
